﻿Imports DTO
Public Class DAWorkData

    Inherits DataProvider

    Shared Sub ConfigServerName(ByVal serverName As String)

        ' call constructor base class
        ConfigServer(serverName)

    End Sub
    '/******************************************************************/
    '/*                         Insert Workdata                        */
    '/******************************************************************/
    'Shared Function InsertAlarm(ByVal dtoAlarm As DTOAlarm) As Integer
    '    Return Update("insertAlarm", {"@alarmNo", "@machineNo", "@alarmTime", "@createDateTime", "@updateDateTime"}, {dtoAlarm.AlarmNoProperty, dtoAlarm.MachineNoProperty, dtoAlarm.AlarmTimeProperty, dtoAlarm.CreateDateTimeProperty, dtoAlarm.UpdateDateTimeProperty})
    'End Function

    '/******************************************************************/
    '/*                 Update time to Workdata                  */
    '/******************************************************************/
    Shared Function UpdateTimeToWorkData(ByVal dtoWorkData As DTOWorkData) As Integer

        Return Update("updateTimeToWorkData", {"@employeeNo", "@workDate", "@startTime", "@endTime"}, {dtoWorkData.EmployeeNoProperty, dtoWorkData.WorkDateProperty, dtoWorkData.StartTimeProperty, dtoWorkData.EndTimeProperty})

    End Function

    
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="startTimeA"></param>
    ''' <param name="endTimeA"></param>
    ''' <param name="empNo"></param>
    ''' <param name="workDate"></param>
    ''' <param name="workTime"></param>
    ''' <param name="overtime"></param>
    ''' <param name="lateness"></param>
    ''' <param name="leaveEarly"></param>
    ''' <param name="workdays"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function UpdateCalculateTimeToWorkData(ByVal startTimeA As Object,
                                                    ByVal endTimeA As Object,
                                                    ByVal empNo As String,
                                                    ByVal workDate As String,
                                                    ByVal workTime As Object,
                                                    ByVal overtime As Object,
                                                    ByVal lateness As Object,
                                                    ByVal leaveEarly As Object,
                                                    ByVal workdays As String,
                                                    ByVal restTime As Object) As Integer

        Dim params As String() = New String() {"@startTimeA", "@endTimeA", "@restTime", "@empNo", "@workDate", "@workTime", "@overtime",
                                                "@lateness", "@leaveEarly", "@workDays"}

        Dim values As Object() = New Object() {startTimeA, endTimeA, restTime, empNo, workDate, workTime, overtime,
                                                lateness, leaveEarly, workdays}


        Return Update("UpdateCalculateTimeToWorkData", params, values)



    End Function

    ''' <summary>
    ''' Get All employee work data
    ''' </summary>
    ''' <param name="organNo"></param>
    ''' <param name="strSearch"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetAllEmployeeWorkData(ByVal organNo As String, ByVal strSearch As String, ByVal dFrom As String, ByVal dTo As String) As DataTable

        Return Query("GetAllEmployeeWorkData", New String() {"@organNo", "@str", "@dFrom", "@dTo"}, New Object() {organNo, strSearch, dFrom, dTo})

    End Function


    ''' <summary>
    ''' Get work data of an employee in period of time, yyyyMMdd
    ''' </summary>
    ''' <param name="organNo"></param>
    ''' <param name="dayFrom">yyyyMMdd</param>
    ''' <param name="dayTo">yyyyMMdd</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetWorkData(ByVal organNo As String, ByVal empNo As string ,ByVal dayFrom As String, ByVal dayTo As String) As DataTable

        Dim params As String() = New String() {"@organNo", "@empNo", "@dayFrom", "@dayTo"}

        Dim values As Object() = New Object() {organNo, empNo, dayFrom, dayTo}

        Return Query("GetWorkData", params, values)

    End Function

    ''' <summary>
    ''' Get work data of an employee in period of time, yyyyMMdd
    ''' </summary>
    ''' <param name="dayFrom">yyyyMMdd</param>
    ''' <param name="dayTo">yyyyMMdd</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetWorkData(ByVal empNo As String, ByVal dayFrom As String, ByVal dayTo As String) As DataTable

        Dim params As String() = New String() {"@empNo", "@dayFrom", "@dayTo"}

        Dim values As Object() = New Object() {empNo, dayFrom, dayTo}

        Return Query("GetWorkDataWithoutOrganNo", params, values)

    End Function
    ''' <summary>
    ''' insert work date to database, yyyyMMdd
    ''' </summary>
    ''' <param name="organNo"></param>
    ''' <param name="empNo"></param>
    ''' <param name="workDate"></param>
    '''<param name="dtTimetable"></param>
    ''' <param name="workContract"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function InsertWorkDate(ByVal organNo As String, ByVal empNo As String,
                                   ByVal exFrom As String, ByVal exTo As String, ByVal workDate As String,
                                   ByVal dtTimetable As DataTable, ByVal workContract As Integer) As Integer

        ' get timetable No, timetable  ex from, timetable ex to, start time, end time
        'Dim dtTimetable As DataTable = GetTimetableEmployee(empNo, exFrom, exTo)


        Dim params As String() = New String() {"@organNo", "@empNo", "@workDate", "@timetableNo",
                                              "@timetableExFrom", "@timetableExTo", "@workContract"}

        Dim values As Object() = New Object() {organNo, empNo, workDate, dtTimetable.Rows.Item(0).Item("TIME_TABLE_NO"),
                                               dtTimetable.Rows.Item(0).Item("EXPIRATION_FROM_TIME_TABLE"),
                                               dtTimetable.Rows.Item(0).Item("EXPIRATION_TO_TIME_TABLE"), workContract}

        Return Update("InsertWorkDate", params, values)

    End Function


    ''' <summary>
    ''' Get Timetable of employee, timetable no, ex from, ex to, start time, end time
    ''' </summary>
    ''' <param name="empNo"></param>
    ''' <param name="exFrom"></param>
    ''' <param name="exTo"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetTimetableEmployee(ByVal empNo As String, ByVal exFrom As String, ByVal exTo As String) As DataTable

        Dim params As String() = New String() {"@empNo", "@exFrom", "@exTo"}

        Dim values As Object() = New Object() {empNo, exFrom, exTo}

        Return Query("GetTimetableEmployee", params, values)


    End Function

    Shared Function UpdateWorkData(ByVal startTime As Object,
                           ByVal endTime As Object,
                           ByVal startTimeA As Object,
                           ByVal endTimeA As Object,
                           ByVal timetableNo As String,
                           ByVal exFrom As String,
                           ByVal exTo As String,
                           ByVal restTime As Object,
                           ByVal organNo As String,
                           ByVal empNo As String,
                           ByVal workDate As String,
                           ByVal workTime As Object,
                           ByVal overtime As Object,
                           ByVal lateness As Object,
                           ByVal leaveEarly As Object,
                           ByVal memo As Object,
                           ByVal workDays As Object,
                           ByVal paidVacation As String,
                           ByVal specialHolidays As String,
                           ByVal absenceDays As String,
                           ByVal holidayDays As String,
                           ByVal compensatoryDayOff As String,
                           ByVal workTypeNo As String,
                           ByVal workContract As Object,
                           ByVal holidayTime As Object) As Integer


        Dim params As String() = New String() {"@startTime", "@endTime", "@startTimeA", "@endTimeA", "@timetableNo", "@exFrom",
                                                "@exTo", "@restTime", "@organNo", "@empNo", "@workDate", "@workTime", "@overtime",
                                                "@lateness", "@leaveEarly", "@memo", "@workDays", "@paidVacation", "@specialHolidays",
                                                "@absenceDays", "@holidayDays", "@compensatoryDayOff", "@workTypeNo", "@contractTime",
                                               "@holidayTime"}

        Dim values As Object() = New Object() {startTime, endTime, startTimeA, endTimeA, timetableNo, exFrom,
                                                exTo, restTime, organNo, empNo, workDate, workTime, overtime,
                                                lateness, leaveEarly, memo, workDays, paidVacation, specialHolidays,
                                                absenceDays, holidayDays, compensatoryDayOff, workTypeNo, workContract, holidayTime}


        Return Update("UpdateWorkData", params, values)

    End Function


    ''' <summary>
    ''' get timetable from work data
    ''' </summary>
    ''' <param name="employeeNo"></param>
    ''' <param name="workDate"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetTimetableFromWorkData(ByVal employeeNo As String, ByVal workDate As Integer) As DataTable


        Return Query("GetTimetableFromWorkData", New String() {"@empNo", "@workDate"}, New Object() {employeeNo, workDate})

    End Function

    ''' <summary>
    ''' chekc working of situation in a particular day
    ''' </summary>
    ''' <param name="organNo"></param>
    ''' <param name="empNo"></param>
    ''' <param name="day"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function CheckWorkSituation(ByVal organNo As String, ByVal empNo As String, ByVal day As String) As Integer
        
        Dim params As String() = New String() {"@organNo", "@empNo", "@day"}

        Dim values As Object() = New Object() {organNo, empNo, day}

        Return NonQueryReturn("CheckWorkSituation", params, values)

    End Function

End Class
